home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / m2 / Turbo_1.lha / modula / docs / EXTENSIONS.DOC < prev    next >
Text File  |  1995-01-24  |  21KB  |  585 lines

  1.              Compiler Extensions
  2.              ===================
  3.  
  4.     The compiler has been extended with extra features. Most of which are
  5.     designed to make interfacing with the amiga operating system easier.
  6.     Other features are designed to make programming in Modula-2 less annoying.
  7.     Avoid using these extensions if you wish to develop portable modules.
  8.  
  9. Underscore
  10. ==========
  11.  
  12.     The underscore is a valid 'letter'.
  13.     eg, '_Turbo_Modula_2' is a legal identifier.
  14.  
  15. SHORTCARD, SHORTINT AND SHORTREAL
  16. =================================
  17.  
  18.     The types SHORTINT, SHORTCARD & SHORTREAL are not normally
  19.     predeclared in other Modula-2 compilers:
  20.  
  21.     SHORTCARD is predeclared as [0..255]    (* byte sized cardinal *)
  22.     SHORTINT  is predeclared as [-128..127] (* byte sized integer  *)
  23.     SHORTREAL Motorola fast floating point.
  24.  
  25. Conversion Rules
  26. ================
  27.  
  28.     Signed (integer) and unsigned(cardinal) numeric subrange types may be freely
  29.     mixed in expressions. The following conversion rules apply:
  30.  
  31.     VAR
  32.       shortint  : SHORTINT  ;
  33.       shortcard : SHORTCARD ;
  34.       integer   : INTEGER ;
  35.       ...
  36.  
  37.     shortcard+shortint  => VAL(INTEGER,shortcard)+VAL(INTEGER,shortint)
  38.     shortcard+integer    => VAL(INTEGER,shortcard)+integer
  39.     shortcard+longint   => VAL(LONGINT,shortcard)+longint
  40.  
  41.     cardinal+shortint   => VAL(LONGINT,cardinal)+VAL(LONGINT,shortint)
  42.     cardinal+integer    => VAL(LONGINT,cardinal)+VAL(LONGINT,integer)
  43.     cardinal+longint    => VAL(LONGINT,cardinal)+longint
  44.  
  45.     longcard+longint    => VAL(LONGINT,longcard)+VAL(LONGINT,shortint)
  46.     longcard+integer    => VAL(LONGINT,longcard)+VAL(LONGINT,integer)
  47.     longcard+longint    => VAL(LONGINT,longcard)+longint
  48.  
  49.     shortint+integer    => VAL(INTEGER,shortint)+integer
  50.     shortint+longint    => VAL(LONGINT,shortint)+longint
  51.  
  52.     shortcard+cardinal    => VAL(CARDINAL,shortcard)+cardinal
  53.  
  54.     integer+longint    => VAL(LONGINT,integer)+longint
  55.  
  56.     Where '+' could be any binary operator.
  57.     The result type in each conversion should be obvious.
  58.  
  59.     Standard function ORD() always returns a LONGINT typed value.
  60.     This may lead to unessacary coerctions, so its always better to use
  61.     VAL() instead.
  62.  
  63. Qualified import identifier aliasing
  64. ====================================
  65.  
  66.     An imported global module name may be aliased.
  67.  
  68.     IMPORT Graphics , Intuition ;
  69.  
  70.     VAR
  71.       rp  : Graphics.RastPortPtr ;
  72.       win : Intuition.WindowPtr ;
  73.  
  74.     Can be rewritten:
  75.  
  76.     IMPORT G := Graphics , I := Intuition ;
  77.  
  78.     VAR
  79.       rp  : G.RastPortPtr ;
  80.       win : I.WindowPtr ;
  81.  
  82.     In V1.2 of the compiler, idenfifiers imported in local modules can also
  83.     be aliased.
  84.  
  85. Imported library versions
  86. =========================
  87.  
  88.     When importing an Amiga library module ( Dos, Intuition, Graphics etc ),
  89.     an optional version number can be specified:
  90.  
  91.     IMPORT Intuition{33} ;
  92.  
  93.     FROM Dos{36} IMPORT System ;
  94.  
  95.     The values 33 & 36 will be passed to Exec.OpenLibrary by Intuition.o & Dos.o
  96.     If no version number is specified, zero is assumed.
  97.  
  98.     Intuition.o, Dos.o etc will cache the highest version opened so far
  99.     in order to reduce calls to Exec.OpenLibrary.
  100.  
  101.     The version number must be a decimal literal (not an arbitrary expression)
  102.     this simplifies the parser in programs like M2B.
  103.  
  104. Structure assignment
  105. ====================
  106.  
  107.     It is possible to assign to an array or record structure in a single
  108.     statement, the right hand side being a list of bracketed expressions.
  109.  
  110.     The syntax of the assignment statement is extended to:
  111.  
  112.     $ assignment  =  designator ":=" ass_rhs .
  113.     $ ass_rhs  = "["[asslist]"]" | expression.
  114.     $ asslist = ass_rhs{,ass_rhs}
  115.  
  116.     VAR x : ARRAY [0..6] OF INTEGER ;
  117.  
  118.     x := [f(y),2,4,a,0,0,0] ; (* The expressions need NOT be constant *)
  119.  
  120.     Trailing elements/fields need not be assigned to,in which case they will
  121.     be zeroed.Any automatically inserted compiler padding fields will also be 0.
  122.  
  123.     x := [f(y),2,4,a] ; (* same as above *)
  124.  
  125.     If a record contains variant fields then the compiler assumes (and type
  126.     checks against) the first variant.In other words you can only assign to the
  127.     first variant field(s).
  128.  
  129.     examples:
  130.  
  131.     VAR
  132.       matrix  = ARRAY [0..3],[0..2],[0..2] OF LONGINT  ;
  133.  
  134.     PROCEDURE InitMatrix ;
  135.     BEGIN
  136.       matrix:=[[[7FFFH,   0,   0],[    0,7FFFH,   0],[    0,    0,7FFFH]],
  137.            [[32642,   0,2856],[    0,7FFFH,   0],[-2856,    0,32642]],
  138.            [[32642,2856,   0],[-2856,32642,   0],[    0,    0,7FFFH]],
  139.            [[7FFFH,   0,   0],[    0,32642,2856],[    0,-2856,32642]]] ;
  140.     END InitMatrix ;
  141.  
  142.     TYPE
  143.       NewMenu = RECORD (* Gadtools structure *)
  144.         nm_Type         : SHORTCARD ;
  145.         CASE : INTEGER OF
  146.         | 0 : nm_Label     : STRING   ;
  147.         | 1 : nm_Image     : ImagePtr ;
  148.         END ;
  149.         nm_CommKey     : STRING  ;
  150.         nm_Flags     : BITSET  ;
  151.         nm_MutualExclude : LONGINT ;
  152.         nm_UserData     : ADDRESS ;
  153.       END ;
  154.  
  155.     VAR
  156.       demomenu : ARRAY [0..11] OF NewMenu ;
  157.  
  158.     BEGIN
  159.       demomenu :=
  160.          [
  161.           [ NM_TITLE,"Project" ],
  162.       [ NM_ITEM, "Run",               "R", {}, 0, MENU_RUN   ],
  163.       [ NM_ITEM, "Step",              "S", {}, 0, MENU_STEP  ],
  164.       [ NM_ITEM, NM_BARLABEL ],
  165.       [ NM_ITEM, "Slower Horizontal", "1", {}, 0, MENU_HSLOW ],
  166.       [ NM_ITEM, "Faster Horizontal", "2", {}, 0, MENU_HFAST ],
  167.       [ NM_ITEM, "Slower Vertical",   "3", {}, 0, MENU_VSLOW ],
  168.       [ NM_ITEM, "Faster Vertical",   "4", {}, 0, MENU_VFAST ],
  169.       [ NM_ITEM, NM_BARLABEL ],
  170.       [ NM_ITEM, "Quit",              "Q", {}, 0, MENU_QUIT  ],
  171.        [ NM_END ]
  172.       ] ;
  173.  
  174. Open array heap variables
  175. =========================
  176.  
  177.     In Modula-2 it is possible to declare open arrays only as formal parameters.
  178.     The compiler allows open arrays to be declared as pointer base types.
  179.  
  180.     VAR
  181.       p : POINTER TO ARRAY OF CHAR ;
  182.  
  183.     Like formal parameters, the open array must be 1 dimensional.
  184.  
  185.     The NEW substitution mechanism has to be extended to allow declarations
  186.     of such heap variables.
  187.  
  188.     NEW(p,exp) ; where exp is an integer/cardinal expression.
  189.  
  190.     This expands to ALLOCATE( p , exp*SIZE(p^[0]));
  191.  
  192.     There is no bounds checking associated with this type of array.
  193.     It is not possible to do any operation on the open array,only individual
  194.     elements may be accessed:
  195.  
  196.       The designator p^ may never appear on its own, the '^' must always be
  197.       followed by a '[' eg p^[10].
  198.  
  199.     If the follow declarations exist:
  200.  
  201.       VAR
  202.         x : POINTER TO ARRAY OF type ;
  203.         y : ARRAY [low..hi] OF type ; (* normal array *)
  204.  
  205.     Then the assignment
  206.  
  207.      x := y ; is allowed. This is equivalent to
  208.      x := ADR( y ) ;
  209.  
  210.      If the base type of the open array(x^[0]) is CHAR then,
  211.  
  212.      x := "help" ;      is allowed and is equivalent to
  213.      x := ADR("help") ;
  214.  
  215.      The SYSTEM.STRING type is predeclared as POINTER TO ARRAY OF CHAR.
  216.      The array pointed to by a STRING variable should always be 0C terminated.
  217.  
  218.      This kind of pointer occurs in the C language, and so is quite useful
  219.      when programming with the amiga OS and the Ansi C libraries. However it is
  220.      not true to Modula's strong typing philosophy and therefore its
  221.      indiscriminate use should be avoided.
  222.  
  223. Pointer casting in selector lists
  224. =================================
  225.  
  226.     It is possible to insert type casts in variable selector lists:
  227.  
  228.     foo := bar(NewMenuPtr)^.nm_Label(ImagePtr) ;
  229.  
  230.     The syntax of the designator is extended to:
  231.  
  232.     $ designator = qualident {"."ident|"["ExpList"]"|"("qualident")"| "^" }.
  233.  
  234.     This method of casting is restricted to (and from) pointer types.
  235.     It is very useful when using Intuitions BOOPSI system.
  236.  
  237. Variable length argument lists
  238. ==============================
  239.  
  240.     A procedure may be declared to take a variable number of arguments.
  241.     To declare such a procedure, the formal parameter list must end with '..':
  242.  
  243.     PROCEDURE VarArgsProc( x : INTEGER ; .. ) ;
  244.     (* There must be at least 1 normal formal parameter *)
  245.  
  246.     There is no standard way of accessing the unknown parameters from Modula-2.
  247.     This kind of declaration normally occur in Amiga OS & C interface modules.
  248.     However you can declare them in implementation & program modules:
  249.  
  250.     PROCEDURE CreateGad( kind:LONGINT; VAR ng:GT.NewGadget; tag1:LONGINT; .. ) ;
  251.     (* topazAttr, visualInfo, window, lastAdded are global variables *)
  252.     BEGIN
  253.       ng.ng_TextAttr    := ADR( topazAttr ) ;
  254.       ng.ng_VisualInfo  := visualInfo ;
  255.       INC( ng.ng_LeftEdge, window^.BorderLeft ) ;
  256.       INC( ng.ng_TopEdge , window^.BorderTop  ) ;
  257.  
  258.       lastAdded := GT.CreateGadgetA( kind, lastAdded, ng, ADR( tag1 ) )
  259.     END CreateGad ;
  260.  
  261.     If a SHORTREAL or REAL actual corresponds to a '..' formal
  262.     then the parameter is converted to a LONGREAL before being passed.
  263.  
  264. Newline and tab characters
  265. ==========================
  266.  
  267.     String literals may contain newline (\n) & tab(\t) characters.
  268.  
  269.     InOut.WriteString("Hello\tworld\n");
  270.  
  271.     If '\' in a string is not followed by one of 't' 'n' '\' then the compiler
  272.     will report an error.
  273.     To represent '\' use '\\'.
  274.  
  275.     "\n" & "\t" are also legal character constants as well as strings.
  276.  
  277. Exit codes
  278. ==========
  279.  
  280.     A return statement inside the initialization statement sequence of the root
  281.     program module may contain an optional integer expression. This expression,
  282.     if executed, will represent the return code for the program.
  283.     If no expression is supplied, or if execution falls through, 0 is returned.
  284.  
  285.     MODULE foo ;
  286.      ...
  287.     BEGIN
  288.       RETURN 20
  289.     END foo.
  290.  
  291.     The standard AmigaDOS return codes are:
  292.  
  293.     00: success
  294.     05: warning
  295.     10: something's wrong
  296.     20: complete or severe failure
  297.  
  298.     Alternatively StdLib.exit(X), will terminate the program with return code X.
  299.  
  300. Coroutines
  301. ==========
  302.  
  303.     The pseudo module SYSTEM does not contain any coroutine facilities,
  304.     instead the library module 'Coroutines' should be used
  305.     (modula:m2lib/Coroutines.def).
  306.  
  307. SHORTSET BITSET & LONGSET constants
  308. ===================================
  309.  
  310.     The compiler predefines 3 set types.
  311.  
  312.     SHORTSET = SET OF [0..07] ; SIZE = 1 Byte
  313.     BITSET   = SET OF [0..15] ; SIZE = 2 Byte
  314.     LONGSET  = SET OF [0..31] ; SIZE = 4 Byte
  315.  
  316.     The type of an unqualified set constant has been extended to support these
  317.     types.
  318.  
  319.        {}, {0}, {0,1} ... {0..7} are compatible with SHORTSET,BITSET & LONGSET
  320.        {8}, {8,9} ... {8..15} are compatible with BITSET & LONGSET
  321.        {16} .. {16..31} are only LONGSETs
  322.  
  323.        By compatible I mean both expression compatible & assignment compatible.
  324.  
  325.     VAR
  326.       shortset : SHORTSET ; bitset : BITSET ; longset  : LONGSET  ;
  327.  
  328.     shortset:= {1} (*valid*); shortset:= {8} (*wrong*); shortset:= {16}(*wrong*)
  329.     bitset  := {1} (*valid*); bitset  := {8} (*valid*); bitset  := {16}(*wrong*)
  330.     longset := {1} (*valid*); longset := {8} (*valid*); longset := {16}(*valid*)
  331.  
  332. INCL & EXCL
  333. ===========
  334.  
  335.     As well as the normal definitions of the standard procedures INCL/EXCL
  336.     the second parameter of these procedures may be a set expression.
  337.  
  338.     example:
  339.  
  340.       INCL(bitset,{1,2}) is identical to bitset := bitset+{1,2}.
  341.       EXCL(bitset,{1,2}) is identical to bitset := bitset-{1,2}.
  342.  
  343.       However the INCL/EXCL versions generate atomic code.
  344.  
  345. BCPL pointers
  346. =============
  347.  
  348.     The DOS operating subsystem was partly implemented in the BCPL programming
  349.     language, which used long word pointers,as opposed to normal byte pointers.
  350.     It is possible to declare a BCPL long word pointer in Turbo Modula-2
  351.  
  352.     TYPE
  353.       FileLockPtr = BCPL POINTER TO FileLock ; (* BCPL is a reserved keyword *)
  354.  
  355.     Instances of this pointer can be dereferenced as normal.
  356.  
  357.     The type SYSTEM.BADDRESS exists and is analogous to the normal
  358.     SYSTEM.ADDRESS type.
  359.  
  360.     If an assignment to a BCPL pointer from an ADDRESS typed expression occurs
  361.     then the compiler will automatically perform the necessary conversion:
  362.  
  363.     VAR lock : FileLockPtr ; v : FileLock ;
  364.  
  365.       lock := ADR(v) ; (* will work, but only if v is long word aligned *)
  366.  
  367.     The reverse assignment from a BADDRESS expression to a normal pointer will
  368.     also be converted properly.
  369.  
  370.     You must be careful not to cast between the 2 different kinds of pointers
  371.     as no conversion will take place. Instead there are 2 functions in the
  372.     SYSTEM module that can be used.
  373.  
  374.     PROCEDURE SYSTEM.BTOA( bp : BADDRESS ) : ADDRESS ;
  375.     PROCEDURE SYSTEM.ATOB(  p : ADDRESS  ) : BADDRESS ;
  376.  
  377.     The base variable of a BCPL pointer should always be long word aligned.
  378.     Modula-2 global variables are always longword aligned as is the memory
  379.     allocated using the StdLib.malloc & Storage.ALLOCATE functions.
  380.  
  381. SHORTFLOAT & LONGFLOAT
  382. ======================
  383.  
  384.     As well as the normal FLOAT conversion function, which always converts
  385.     to REAL, there are 2 other integer/cardinal->real conversion functions:
  386.  
  387.     SHORTFLOAT, converts an integer/cardinal into a SHORTREAL
  388.     LONGFLOAT , converts an integer/cardinal into a LONGREAL
  389.  
  390. Psuedo Module SYSTEM
  391. ====================
  392.  
  393.   The following types are declared in SYSTEM:
  394.  
  395.     ADDRESS
  396.     BADDRESS    see above
  397.     BYTE
  398.     WORD
  399.     LONGWORD    like BYTE & WORD except 32-bits long
  400.  
  401.     SHORTSET    (also pervasive)
  402.     BITSET        (also pervasive)
  403.     LONGSET        (also pervasive)
  404.     SHORTREAL    (also pervasive)
  405.     FFP        Motoral Fast Floating Point (FFP=SHORTREAL)
  406.     STRING        see above
  407.  
  408.     Note that ADDRESS is internally declared as [0..2^31-1], however no
  409.     range checking is ever applied on ADDRESS variables so its possible to
  410.     assume all 32-bits.
  411.     Be careful when mixing ADDRESS expressions with signed expressions, as the
  412.     compiler will corece the ADDRESS to a LONGINT:
  413.  
  414.     address+longint => VAL(LONGINT,address)+longint
  415.  
  416.     If you want the result to be unsigned then you must corece the signed
  417.     expression into  ADDRESS or LONGCARD type using VAL:
  418.  
  419.     address+VAL(ADDRESS,longint)
  420.  
  421.   Functions declared in SYSTEM:
  422.   -----------------------------
  423.  
  424.     ADR
  425.     TSIZE
  426.     BTOA        see above
  427.     ATOB        see above
  428.  
  429.     OFFSET        OFFSET( recordType , field ) : LONGINT
  430.             Returns the byte offset of the field in the record.
  431.  
  432.     CAST        CAST( TYPEid,expression) : TYPEid
  433.             Performs a typecast: same as to TYPEid(expression).
  434.             eg str := CAST(STRING,98)
  435.                str := STRING(98)
  436.  
  437.     MAKEID        MAKEID( STRING ) : LONGINT
  438.             String should <= 4 characters.
  439.  
  440. Comment Options
  441. ===============
  442.  
  443.     Unnested comments in your source code can be used to override command line
  444.     options. The format is (* @X+ *) to enable an option or (* @X- *) to disable
  445.     it. These comments should normally be placed at the top of your code.
  446.  
  447.     The options are:
  448.  
  449.     @C(+/-)    Enable/Disable Large Code option.
  450.     @D(+/-)    Enable/Disable Large Data option.
  451.     @B(+/-)    Enable/Disable Array Bounds Checking.
  452.     @R(+/-)    Enable/Disable Range Checking.
  453.     @V(+/-)    Enable/Disable OVerflow Checking.
  454.     @S(+/-)    Enable/Disable Stack Checking.
  455.     @Z(+/-)    Enable/Disable Integer Divide by 0 Checking.
  456.     @P(+/-)    Enable/Disable Pointer Checking.
  457.     @A(+/-)    Enable/Disable Alternative BSS naming convention.
  458.  
  459.     There are also two other options which relate to individual procedures:
  460.  
  461.     @G See examples/src/Hook.mod
  462.     @O See ansi-c/SetJmp.def
  463.  
  464.     Procedure switches should be placed between the procedure keyword & the
  465.     procedure name:
  466.  
  467.     PROCEDURE (* @G *) CallBack( ) ;
  468.     BEGIN ...
  469.  
  470.     The @G comment tells the compiler to generates code to set the A4 register
  471.     to point to the global variable space when the procedure is entered
  472.     (the old value is saved on entry an restored at exit), this is required
  473.     if your program performs out of context calls when using the small data
  474.     addressing model.
  475.     You MUST use @G on procedures that are passed to the operating system
  476.     for later invocation, eg Hook functions, CreateTask entry points etc.
  477.     Unfortunately using @G means the program can not be made resident.
  478.  
  479.     The @O comement tells to the compiler not to allocate any locals to
  480.     registers (not needed unless you use the SetJmp functions).
  481.  
  482.     When an open array is passed by value, the caller normally passes its
  483.     address via the stack, its then the callees job to make a copy of it.
  484.     The copying can be suppressed by using (* @N *) option, this option applies
  485.     to a parameter list, it should be placed just afer the ':'
  486.  
  487.     PROCEDURE X( a , b : (*@N*) ARRAY OF CHAR ; c : ARRAY OF CHAR ) ;
  488.     BEGIN
  489.  
  490.     In the above a & b will not be copied, while c will be.
  491.  
  492.     Use @N for efficiency if you know an open array value parameter will be
  493.     strictly read-only. You must be careful, since it effectively converts
  494.     value parameters into variable parameters, bypassing the compiler's normal
  495.     safety checks. The PROGRAMMER must make sure not to make any assignments to
  496.     such parameters, otherwise undesirable side effects may occur.
  497.  
  498.     The @G @O @N comments should only be used in a declaration for
  499.     an implementation NOT in any forward declaration or definition module
  500.     (in which case they will be ignored).
  501.  
  502. DEFINITION FOR C MODULE'S
  503. =========================
  504.  
  505.     To make it easy to interface with code written in the 'C' language it
  506.     is possible to declare non standard definition modules.
  507.     There are 3 closely related kinds:
  508.  
  509.     1.DEFINITION FOR C MODULE (eg StdLib.def)
  510.  
  511.       There is no corresponding implementation module.
  512.       This kind of definition module normally contains a list of declarations
  513.       which are defined in some C library or object file.
  514.       A normal Modula-2 module that wishes to use the functions/variables
  515.       declared in this kind of module simply imports them as normal.
  516.       To enable correct linking however, the library or object files must be
  517.       specified on the command line
  518.  
  519.       >m2b CallsX.mod X.o X.lib
  520.  
  521.       See examples/for_c/ for an example of calling a 'C' function.
  522.  
  523.       The library (c.lib) which contains all the function declared in
  524.       StdLib.def,CType.def etc is automatically included by DCC,
  525.       so we dont have to specify it on the command line.
  526.  
  527.       Note that function procedures declared in this kind of module can be
  528.       treated as proper procedures (ie the function result can be ignored).
  529.  
  530.     2.DEFINITION FOR AMIGALIB MODULE (eg Console.def)
  531.  
  532.       Mainly used to interface with AmigaDos devices (functions in amiga.lib).
  533.       Like FOR C except all variable and strings declarations declared in the
  534.       definition module are expected to be found in the coressponding Modula-2
  535.       object file. For the compiler to generate such an object file there must
  536.       be a corressonding implementation module,which is normally empty
  537.       eg Console.mod or opens the device.
  538.       The implementation module may contain procedure declaration which
  539.       should only impelement macros not coded in the object file or library
  540.       eg StdIO.mod .
  541.  
  542.     3.DEFINITION FOR LIBRARY MODULE (eg GadTools.def)
  543.  
  544.       Used to open and interface to AmigaDos libraries.
  545.       Identical to FOR AMIGALIB except when such a module is imported an
  546.       optional library version number can be specified (see line 75 above).
  547.       This version number can be read using the pervasive cardinal variable
  548.       'VERSION', for an example see GadTools.mod, and is noramlly passed to
  549.       to function OpenLib, which inturn calls Exec.OpenLibrary.
  550.       The initialisation body of an implementaion for library module must be
  551.       capable of being called more than once i.e. with different versions
  552.       arguments.
  553.  
  554. Clean up code 'CLOSE'
  555. =====================
  556.  
  557.     In order to free any allocated resources (files, memory etc) a module may
  558.     contain a CLOSE area:
  559.  
  560.     MODULE Test ;
  561.  
  562.     FROM Exec IMPORT AllocMem, FreeMem ;
  563.  
  564.     VAR
  565.       x : POINTER TO INTEGER ;
  566.  
  567.     BEGIN
  568.       x := AllocMem( 2 )
  569.     CLOSE (* optional *)
  570.       IF x # NIL THEN FreeMem( x ) END
  571.     END Test.
  572.  
  573.     A CLOSE area is allowed in every module and is called when the program
  574.     terminates (either succesfully or through a runtime error).
  575.     The order in which the CLOSE statement sequences are called is the exact
  576.     opposite to to the initialisation body calling order. i.e. the main modules
  577.     CLOSE sequence is called first...
  578.     A CLOSE statement sequence cannot be declared for procedures or local
  579.     modules.
  580.     The CLOSE mechanism is implemented using StdLib.atexit, which can be
  581.     called directly if you prefer.
  582.     Make sure that the CLOSE statements cannot fail (cause a run-time error),
  583.     as this will result in an unbreakable loop.
  584.     CLOSE is a reserved keyword.
  585.